package com.feeyin.radar.msg.controller;

import com.feeyin.radar.commons.Page;
import com.feeyin.radar.commons.StringUtils;
import com.feeyin.radar.msg.service.WarningInfoService;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import org.springframework.web.servlet.view.RedirectView;

public class AuditRemindController extends MultiActionController
{
  private WarningInfoService warningInfoService;
  private String auditRemind;

  public WarningInfoService getWarningInfoService()
  {
    return this.warningInfoService;
  }

  public void setWarningInfoService(WarningInfoService warningInfoService) {
    this.warningInfoService = warningInfoService;
  }

  public String getAuditRemind() {
    return this.auditRemind;
  }

  public void setAuditRemind(String auditRemind) {
    this.auditRemind = auditRemind;
  }

  public ModelAndView display(HttpServletRequest request, HttpServletResponse response)
  {
    Map model = new HashMap();
    model.put("result", request.getParameter("result"));

    String auditAllInvoice = (String)request.getSession().getAttribute("isAuditAllInvoice");
    String auditDeptInvoice = (String)request.getSession().getAttribute("isAuditDeptInvoice");
    Integer userId = (Integer)request.getSession().getAttribute("userId");
    int sign = 0;
    if ((!StringUtils.isEmpty(auditAllInvoice)) && ("1".equals(auditAllInvoice)))
      sign = 1;
    else if ((!StringUtils.isEmpty(auditDeptInvoice)) && ("1".equals(auditDeptInvoice))) {
      sign = 2;
    }

    Page page = new Page();
    page.getPageList(this.warningInfoService.getPageAuditWarningInfosCountByUserId(userId, sign).intValue(), null, request);
    model.put("warningInfos", this.warningInfoService.getPageAuditWarningInfosByUserId(userId, page, sign));
    return new ModelAndView(getAuditRemind(), model);
  }

  public ModelAndView readedAuditInfo(HttpServletRequest request, HttpServletResponse response)
  {
    boolean result = false;
    int success = 0;
    String[] ids = request.getParameterValues("id");
    if ((ids != null) && (ids.length > 0)) {
      result = this.warningInfoService.updateWarningInfoForReaded(ids, 0);
      if (result) success = 1;
    }

    return new ModelAndView(new RedirectView("./auditRemind.do?action=display&result=" + success));
  }

  public ModelAndView deleteAuditInfo(HttpServletRequest request, HttpServletResponse response)
  {
    boolean result = false;
    int success = 0;
    String[] ids = request.getParameterValues("id");
    if ((ids != null) && (ids.length > 0)) {
      result = this.warningInfoService.deleteWarningInfo(ids);
      if (result) success = 1;
    }

    return new ModelAndView(new RedirectView("./auditRemind.do?action=display&result=" + success));
  }
}